//
//  TestReuseableCell.swift
//  ADKit_Example
//
//  Created by Adoma on 2023/12/27.
//  Copyright © 2023 CocoaPods. All rights reserved.
//

import ADKit
import RxSwift
import RxCocoa

class TestReuseableCellController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .random
        
        let table = UITableView()
//        table.delegate = self
//        table.dataSource = self
        
        table.register(ClassTableCell.self)
        table.register(TestNibTableViewCell.self)
        
        view.addSubview(table)
        table.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        Observable.just([1,1,1,1]).bind(to: table.rx.items(ClassTableCell.self)) { i, element, cell in
            
        }.disposed(by: rx.disposeBag)
        
        let collection = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewLayout().then({ layout in
            
        }))
        collection.register(UICollectionReusableView.self, kind: .header)
    }
    
    class ClassTableCell: UITableViewCell {
        
        override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
            super.init(style: style, reuseIdentifier: reuseIdentifier)
            contentView.backgroundColor = .random
        }
        
        required init?(coder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
    }
}

extension TestReuseableCellController: UITableViewDelegate, UITableViewDataSource {
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 0 {
            let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as ClassTableCell
            return cell
        }
        let cell = tableView.dequeueReusableCell(forIndexPath: indexPath) as TestNibTableViewCell
        return cell
    }
}
